<template>
  <div class="login-container">
    <img class="pr" src="../../assets/u4.png">
    <img class="pt" src="../../assets/u3.png">
    <img class="pl" src="../../assets/u5.png">
    <div class="login">
      <div class="login-left"><img src="../../assets/ok.png" alt=""></div>
      <div class="login-right">
        <div class="head">
          <img src="../../assets/u24.png" alt="">
          <span>电商后台管理</span>
        </div>
        <el-form ref="loginForm" :rules="rules" :model="loginForm" width="300px">
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" prefix-icon="el-icon-user" placeholder="账户" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" placeholder="密码" show-password />
          </el-form-item>
          <el-form-item prop="verify">
            <el-row>
              <el-col :span="16"><el-input v-model="loginForm.verify" prefix-icon="el-icon-umbrella" placeholder="验证码" /></el-col>
              <el-col :span="8"><div class="yanzhengma">5  7  6  8</div></el-col>
            </el-row>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="width:361px" @click="submitForm('loginForm')">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoginBtn',
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
        verify: ''
      },
      verifyCode: 5768,
      rules: {
        username: [
          { required: true, message: '用户名', trigger: 'blur' },
          { min: 5, message: '长度在不少于 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码', trigger: 'blur' },
          { min: 5, message: '长度在不少于 5 个字符', trigger: 'blur' }
        ],
        verify: [
          { required: true, message: '验证码', trigger: 'blur' },
          { min: 4, max: 4, message: '输入有误,请重新输入', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          if (+this.loginForm.verify !== this.verifyCode) return this.$message.error('验证码错误!')
          this.$message.success('登陆成功')
          this.$router.push('/')
          // console.log(this.loginForm)
          // 提交后清空表单數據
          this.$refs.loginForm.resetFields()
          // 手动删除登录数据
          this.loginForm = {
            username: '',
            password: '',
            verify: ''
          }
        } else {
          this.$message.error('登录失败!')
          return false
        }
      })
    }

  }
}
</script>

<style lang="scss" scoped>
  .login-container{
  height: 100%;
  width: 100%;
  position: relative;
  background-color: rgba(243, 246, 253, 1);
  background-image: linear-gradient(#3fccfd, #996cfb);
  .pr{
    position: absolute;
    top: -200px;
    right:  400px;
  }
  .pl{
  position: absolute;
  bottom: -10px;
  left: -130px;
  }
  .pt{
    position: absolute;
    top: 50px;
    left: 200px;
  }
  .login{
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-450px,-200px);
    // background-color: pink;
    width: 900px;
    height: 403px;
    display: flex;

    .login-right{
      margin-left: 45px;
      height: 400px;
      width: 400px;
      background-color: #fff;
      justify-content: center;
      padding:  0  20px;

      .head{
        width: 360px;
        height: 120px;
        display: flex;
      justify-content: center;
      align-items: center;
      img{
        height: 42px;
        width: 50px;
      }
      span{
        font-family: "楷体 Bold", "楷体 Regular", 楷体;
        font-weight: 700;
        font-style: normal;
        font-size: 32px;
        color: rgb(67, 141, 238);
        margin-left: 13px;
      }

      }
      .yanzhengma{
       background-color: rgb(204, 204, 204);
       text-align: center;
      border-radius: 0px 4px 4px 0px;
    box-shadow: none;
    font-family: "Arial Negreta", "Arial Normal", Arial;
    font-weight: 700;
    font-style: normal;
    font-size: 20px;
    color: rgb(255, 119, 51);
      }
    }
  }
}

</style>
